package com.example.houduan.common.lang.mail;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.MessagingException;
import javax.swing.*;

public class SendMail {

    // 假设 JavaMailUntil 类和 createSession 方法已经正确定义
    Session session = JavaMailUntil.createSession();

    public String sendEmail(String email) {
        String meg =VerificationCodeGenerator.generateCode(6);
        try {
            // 创建邮件对象
            MimeMessage message = new MimeMessage(session);
            message.setSubject("主题");
            message.setText(meg);
            message.setFrom(new InternetAddress("3270157732@qq.com"));
            message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(email));
            // 发送
            Transport.send(message);
            System.out.println("邮件发送成功");
        } catch (MessagingException e) {
            e.printStackTrace();
            System.out.println("邮件发送失败");
            return "邮件发送失败";
        }
        return meg;
    }


}
